
<!DOCTYPE html>
<html lang="zh-CN" class="app">
	
<!-- Mirrored from easp.jswwl.com/?api/Easp.Db.OpenConnection by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 13 Nov 2021 05:16:49 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
		<meta charset="utf-8" />
		<title>Easp.Db.OpenConnection - EasyASP API 文档</title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
		<link href="../cdn.bootcss.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
		<link href="../cdn.bootcss.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet">		<link href="../cdn.bootcss.com/prettify/r298/prettify.min.css" rel="stylesheet">
		<link rel="stylesheet" href="inc/css/animate.css" type="text/css" />
		<link rel="stylesheet" href="inc/css/simple-line-icons.css" type="text/css" />
		<link rel="stylesheet" href="inc/css/font.css" type="text/css" />
		<link rel="stylesheet" href="inc/css/app.css" type="text/css" />
		<link rel="stylesheet" href="inc/editor/css/editormd.preview.min.css" />
		<!--<link href='http://api.youziku.com/webfont/CSS/57358c19f629d8086c49377f' rel='stylesheet' type='text/css' />-->
		<!--[if lt IE 9]>
			<script src="inc/js/ie/html5shiv.js"></script>
			<script src="inc/js/ie/respond.min.js"></script>
			<script src="inc/js/ie/excanvas.js"></script>
		<![endif]-->
	</head>
	<body>
		<section class="vbox">
			<header class="bg-white-only header header-md navbar navbar-fixed-top-xs">
	<div class="navbar-header aside bg-info dk">
		<a class="btn btn-link visible-xs" data-toggle="class:nav-off-screen,open" data-target="#nav,html"> <i class="icon-list"></i></a>
		<a href="index.html" class="navbar-brand text-lt"> <img src="inc/images/logo.png" alt="."> <span class="hidden-nav-xs m-l-sm english">EasyASP</span></a>
	</div>
	<ul class="nav navbar-nav hidden-xs">
		<li>
			<a href="#nav,.navbar-header" data-toggle="class:nav-xs,nav-xs" class="text-muted"> <i class="fa fa-dedent text"></i><i class="fa fa-indent text-active"></i></a>
		</li>
	</ul>
	<!--<form class="navbar-form navbar-left input-s-lg m-t m-l-n-xs hidden-xs" role="search">
		<div class="form-group">
			<div class="input-group">
				<span class="input-group-btn">
					<button type="button" class="btn btn-sm bg-white btn-icon rounded"><i class="fa fa-search"></i></button>
				</span>
				<input type="text" class="form-control input-sm no-border rounded" id="search" placeholder="Search API">
			</div>
		</div>
	</form>-->
	<ul class="nav nav-pills pull-right topnav hidden-xs">
		<li role="presentation"><a href="http://www.easyasp.cn/" target="_blank">EASP官网</a></li>
		<li role="presentation"><a href="http://www.easyasp.cn/downloads" target="_blank">下载</a></li>
		<li role="presentation"><a href="http://www.easyasp.cn/tutorials" target="_blank">教程</a></li>
		<li role="presentation" class="active"><a href="javascript:;">API文档</a></li>
		<li role="presentation"><a href="http://www.easyasp.cn/plugins" target="_blank">插件</a></li>
		<li role="presentation"><a href="http://bbs.easyasp.cn/" target="_blank">论坛</a></li>
		<li role="presentation"><a href="http://www.easyasp.cn/donate" target="_blank">捐赠</a></li>
	</ul>
</header>
			<section>
				<section class="hbox stretch">
					
<aside class="bg-dark dk aside hidden-print" id="nav">
	<section class="vbox">
		<section class="w-f-md scrollable">
			<div class="slim-scroll" data-height="auto" data-disable-fade-out="true" data-distance="0" data-size="10px" data-railOpacity="0.2">
				<nav class="nav-primary hidden-xs">
					<ul class="nav" data-ride="collapse">
						<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted"></li>
						<li class=""><a href="index368f.html?api/Easp.BasePath" class="auto"><i class="fa-leaf fa"></i><span>基础公共函数</span></a></li>
						<li class="">
							<a href="#" class="auto"><span class="pull-right text-muted"><i class="fa fa-angle-left text"></i><i class="fa fa-angle-down text-active"></i></span><i class="fa-font fa"></i><span>字符串处理</span></a>
							<ul class="nav dk text-sm">
								<li class=""><a href="index19fa.html?api/Easp.Str.EncodeJsonUnicode" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>字符串处理</span></a></li>
								<li class=""><a href="index843b.html?api/StringBuilder.NewLine" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>String Builder</span></a></li>
								<li class=""><a href="indexbede.html?api/Validation.Value" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>表单验证</span></a></li>
							</ul>
						</li>
						<li class=""><a href="index86e2.html?api/Easp.Date.Format" class="auto"><i class="fa-calendar fa"></i><span>日期处理</span></a></li>
						<li class=""><a href="index2520.html?api/Easp.Error.E" class="auto"><i class="fa-bug fa"></i><span>异常处理</span></a></li>
						<li class=""><a href="index3c88.html?api/Easp.Console.Enable" class="auto"><i class="fa-stethoscope fa"></i><span>控制台调试</span></a></li>
						<li class=""><a href="index23ba.html?api/Easp.Var.Var" class="auto"><i class="fa-magic fa"></i><span>超级变量</span></a></li>
						<li class=""><a href="index6241.html?api/Easp.Db.QueryTimes" class="auto"><i class="fa-bars fa"></i><span>数据库操作</span></a></li>
						<li class="">
							<a href="#" class="auto"><span class="pull-right text-muted"><i class="fa fa-angle-left text"></i><i class="fa fa-angle-down text-active"></i></span><i class="fa-truck fa"></i><span>JSON 解析与生成</span></a>
							<ul class="nav dk text-sm">
								<li class=""><a href="index3fac.html?api/Easp.Json.EncodeUnicode" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>JSON 解析与生成</span></a></li>
								<li class=""><a href="index1814.html?api/Object.Get" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>JsonObject 对象</span></a></li>
								<li class=""><a href="indexd2e5.html?api/Array.Get" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>JsonArray 对象</span></a></li>
							</ul>
						</li>
						<li class=""><a href="index0e2b.html?api/Easp.List.New" class="auto"><i class="fa-rocket fa"></i><span>超级数组</span></a></li>
						<li class=""><a href="index8d16.html?api/Easp.Fso.fsoName" class="auto"><i class="fa-copy fa"></i><span>文件系统处理</span></a></li>
						<li class=""><a href="index3006.html?api/Easp.Tpl.FilePath" class="auto"><i class="fa-bolt fa"></i><span>模板引擎</span></a></li>
						<li class=""><a href="indexc31d.html?api/Easp.Tar.SavePath" class="auto"><i class="fa fa-file-zip-o"></i><span>无组件压缩解压</span></a></li>
						<li class="">
							<a href="#" class="auto"><span class="pull-right text-muted"><i class="fa fa-angle-left text"></i><i class="fa fa-angle-down text-active"></i></span><i class="fa-upload fa"></i><span>无组件上传</span></a>
							<ul class="nav dk text-sm">
								<li class=""><a href="index7b7b.html?api/Easp.Upload.AllowMaxSize" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>无组件上传</span></a></li>
								<li class=""><a href="index2627.html?api/File.ContentType" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>文件对象</span></a></li>
							</ul>
						</li>
						<li class=""><a href="index14f8.html?api/Easp.Http.New" class="auto"><i class="icon-link icon"></i><span>远程文件处理</span></a></li>
						<li class="">
							<a href="#" class="auto"><span class="pull-right text-muted"><i class="fa fa-angle-left text"></i><i class="fa fa-angle-down text-active"></i></span><i class="fa-cloud-download fa"></i><span>缓存处理</span></a>
							<ul class="nav dk text-sm">
								<li class=""><a href="index2221.html?api/Easp.Cache.New" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>缓存处理</span></a></li>
								<li class=""><a href="index99f4.html?api/Info.Expires" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>缓存文件操作</span></a></li>
							</ul>
						</li>
						<li class="">
							<a href="#" class="auto"><span class="pull-right text-muted"><i class="fa fa-angle-left text"></i><i class="fa fa-angle-down text-active"></i></span><i class="fa-rss-square fa"></i><span>XML文件处理</span></a>
							<ul class="nav dk text-sm">
								<li class=""><a href="index00fb.html?api/Easp.Xml.Open" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>XML文件处理</span></a></li>
								<li class=""><a href="index27f6.html?api/Node.Dom" class="auto"> <i class="fa fa-angle-right text-xs"></i><span>XML节点对象操作</span></a></li>
							</ul>
						</li>
						<li class=""><a href="index4112.html?api/Easp.Plug.Bs" class="auto"><i class="fa-plug fa"></i><span>拓展插件</span></a></li>
					</ul>
				</nav>
			</div>
		</section>
	</section>
</aside>
					<section id="content">
						<section class="vbox">
							<section class="w-f-md" id="bjax-target">
								<section class="hbox stretch">
<aside class="aside bg-light dk" id="sidebar">
	<section class="vbox animated">
		<section class="scrollable hover">
			<div class="list-group no-radius no-border no-bg auto en class-li">
<a href="index6241.html?api/Easp.Db.QueryTimes" class=" list-group-item property">Easp.Db.QueryTimes</a>
<a href="index48a7.html?api/Easp.Db.PageParam" class=" list-group-item property">Easp.Db.PageParam</a>
<a href="index80ef.html?api/Easp.Db.PageSize" class=" list-group-item property">Easp.Db.PageSize</a>
<a href="index2ff8.html?api/Easp.Db.PageRecordCount" class=" list-group-item property">Easp.Db.PageRecordCount</a>
<a href="index8e15.html?api/Easp.Db.PageCount" class=" list-group-item property">Easp.Db.PageCount</a>
<a href="index6257.html?api/Easp.Db.PageIndex" class=" list-group-item property">Easp.Db.PageIndex</a>
<a href="index4a3b.html?api/Easp.Db.PageCurrentSize" class=" list-group-item property">Easp.Db.PageCurrentSize</a>
<a href="index19da.html?api/Easp.Db.PageMinRow" class=" list-group-item property">Easp.Db.PageMinRow</a>
<a href="indexd6c1.html?api/Easp.Db.PageMaxRow" class=" list-group-item property">Easp.Db.PageMaxRow</a>
<a href="index561c.html?api/Easp.Db.InsertSeparator" class=" list-group-item property">Easp.Db.InsertSeparator</a>
<a href="index66a1.html?api/Easp.Db.DefaultConn" class=" list-group-item property">Easp.Db.DefaultConn</a>
<a href="index38fc.html?api/Easp.Db.OpenConnection" class="active list-group-item method">Easp.Db.OpenConnection</a>
<a href="indexeb3a.html?api/Easp.Db.CreateConnection" class=" list-group-item method">Easp.Db.CreateConnection</a>
<a href="index413c.html?api/Easp.Db.SetConnection" class=" list-group-item method">Easp.Db.SetConnection</a>
<a href="indexc7ef.html?api/Easp.Db.SetConn" class=" list-group-item method">Easp.Db.SetConn</a>
<a href="indexb61c.html?api/Easp.Db.GetConnection" class=" list-group-item method">Easp.Db.GetConnection</a>
<a href="index204c.html?api/Easp.Db.GetConn" class=" list-group-item method">Easp.Db.GetConn</a>
<a href="index51bc.html?api/Easp.Db.GetType" class=" list-group-item method">Easp.Db.GetType</a>
<a href="index8ccd.html?api/Easp.Db.Type" class=" list-group-item method">Easp.Db.Type</a>
<a href="indexcb8f.html?api/Easp.Db.GetVersion" class=" list-group-item method">Easp.Db.GetVersion</a>
<a href="index30db.html?api/Easp.Db.Version" class=" list-group-item method">Easp.Db.Version</a>
<a href="index7e2a.html?api/Easp.Db.GetTypeVersion" class=" list-group-item method">Easp.Db.GetTypeVersion</a>
<a href="index1c5a.html?api/Easp.Db.TypeVersion" class=" list-group-item method">Easp.Db.TypeVersion</a>
<a href="index2db1.html?api/Easp.Db.ToSql" class=" list-group-item method">Easp.Db.ToSql</a>
<a href="index2671.html?api/Easp.Db.ToSqlBatch" class=" list-group-item method">Easp.Db.ToSqlBatch</a>
<a href="index86e2-2.html?api/Easp.Db.Execute" class=" list-group-item method">Easp.Db.Execute</a>
<a href="index1d58.html?api/Easp.Db.Exec" class=" list-group-item method">Easp.Db.Exec</a>
<a href="index22c7.html?api/Easp.Db.Query" class=" list-group-item method">Easp.Db.Query</a>
<a href="index0b05.html?api/Easp.Db.ExecuteBatch" class=" list-group-item method">Easp.Db.ExecuteBatch</a>
<a href="index5d8a.html?api/Easp.Db.ExecBatch" class=" list-group-item method">Easp.Db.ExecBatch</a>
<a href="index36ff.html?api/Easp.Db.Select" class=" list-group-item method">Easp.Db.Select</a>
<a href="index1c53.html?api/Easp.Db.Sel" class=" list-group-item method">Easp.Db.Sel</a>
<a href="indexac9c.html?api/Easp.Db.GetRecordSet" class=" list-group-item method">Easp.Db.GetRecordSet</a>
<a href="index5781.html?api/Easp.Db.GetRS" class=" list-group-item method">Easp.Db.GetRS</a>
<a href="indexba70.html?api/Easp.Db.Pager" class=" list-group-item method">Easp.Db.Pager</a>
<a href="indexe4d5.html?api/Easp.Db.SetPager" class=" list-group-item method">Easp.Db.SetPager</a>
<a href="index3fc0.html?api/Easp.Db.GetPager" class=" list-group-item method">Easp.Db.GetPager</a>
<a href="indexbc08.html?api/Easp.Db.Insert" class=" list-group-item method">Easp.Db.Insert</a>
<a href="index97c9.html?api/Easp.Db.Ins" class=" list-group-item method">Easp.Db.Ins</a>
<a href="index2a3f.html?api/Easp.Db.InsertBatch" class=" list-group-item method">Easp.Db.InsertBatch</a>
<a href="indexaa20.html?api/Easp.Db.InsBatch" class=" list-group-item method">Easp.Db.InsBatch</a>
<a href="index30d3.html?api/Easp.Db.Delete" class=" list-group-item method">Easp.Db.Delete</a>
<a href="indexfcc5.html?api/Easp.Db.Del" class=" list-group-item method">Easp.Db.Del</a>
<a href="index1f00.html?api/Easp.Db.DeleteBatch" class=" list-group-item method">Easp.Db.DeleteBatch</a>
<a href="index4361.html?api/Easp.Db.DelBatch" class=" list-group-item method">Easp.Db.DelBatch</a>
<a href="indexc1d5.html?api/Easp.Db.Update" class=" list-group-item method">Easp.Db.Update</a>
<a href="index90c9.html?api/Easp.Db.Upd" class=" list-group-item method">Easp.Db.Upd</a>
<a href="index640f.html?api/Easp.Db.UpdateBatch" class=" list-group-item method">Easp.Db.UpdateBatch</a>
<a href="index2eaf.html?api/Easp.Db.UpdBatch" class=" list-group-item method">Easp.Db.UpdBatch</a>
<a href="index4d99.html?api/Easp.Db.Close" class=" list-group-item method">Easp.Db.Close</a>
<a href="indexba15.html?api/Easp.Db.BeginTrans" class=" list-group-item method">Easp.Db.BeginTrans</a>
<a href="index266e.html?api/Easp.Db.RollbackTrans" class=" list-group-item method">Easp.Db.RollbackTrans</a>
<a href="indexea00.html?api/Easp.Db.CommitTrans" class=" list-group-item method">Easp.Db.CommitTrans</a>
<a href="index494b.html?api/Easp.Db.Begin" class=" list-group-item method">Easp.Db.Begin</a>
<a href="index3218.html?api/Easp.Db.Rollback" class=" list-group-item method">Easp.Db.Rollback</a>
<a href="indexa977.html?api/Easp.Db.Commit" class=" list-group-item method">Easp.Db.Commit</a>

			</div>
		</section>
	</section>
</aside>
									<section id="content">
										<section class="vbox">
											<section class="w-f-md" id="bjax-target">
												<section class="hbox stretch">
													<aside class="col-lg-6 b-l">

<section class="vbox">

<section class="scrollable padder-v hover m-t m-b" id="test-editormd-view">

<textarea id="append-test" style="display:none;">
## Easp.Db.OpenConnection
方法，生成数据库连接字符串
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-code"></i> 语法</label></h4>

```asp
Easp.Db.OpenConnection(dbType, strDB, strServer)
```
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-cogs"></i> 参数</label></h4>

|参数|类型|说明
| ------------ | ------------ |
|dbType|String(字符串)|数据库类型，可选 `MSSQL` `ACCESS` `MYSQL`
|strDB|String(字符串)|数据库名称，如果连接至 `Access` 数据库，数据库文件可以相对路径也可以是绝对路径
|strServer|String(字符串)|服务器地址及认证信息，写法为：`用户名:密码@服务器地址:端口`，如果连接至 `Access` 数据库，这里为密码，无密码省略此参数
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-reply"></i> 返回值</label></h4>

|类型|说明
| ------------ | ------------ |
|Object(ASP对象)|生成连接字符串并建立数据库连接对象
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-info-circle"></i> 说明</label></h4>

生成连接字符串并建立数据库连接对象。

注：如果要连接到MySQL数据库，服务器需要安装MySQL ODBC驱动（版本5.1），下载地址 http://dev.mysql.com/downloads/connector/odbc/5.1.html
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-plug"></i> 示例</label></h4>

```asp
'连接至MS SQL Server，服务器地址为192.168.0.2，用户名为sa，密码为pass，数据库为TestData'
Set Conn = Easp.Db.OpenConnection("MSSQL","TestData","sa:pass@192.168.0.2")
'连接至MS Access数据库，数据库文件为相对路径，密码为accpass'
Set Conn = Easp.Db.OpenConnection("ACCESS","/data/Test.mdb","accpass")
'连接至MS Access数据库，数据库文件为绝对路径，没有密码'
Set Conn = Easp.Db.OpenConnection("ACCESS","D:\Web\data\Test.mdb","")
'连接至MySQL Server，服务器地址为192.168.0.2，端口为3307，用户名为root，密码为pass，数据库为TestData'
Set Conn = Easp.Db.OpenConnection("MYSQL","TestData","root:pass@192.168.0.2:3307")
```
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-tag"></i> 应用场景 & 使用心得</label></h4>

关于EASP的数据库连接，我们需要知道它一共两种连接的方法：
#### 系统默认数据库连接
所谓默认就是我们如果只使用一个数据库进行开发，那么我们就只是用到这一个数据库连接，系统中所有关于查询插入更新删除的操作都是基于这个连接进行。
#### 附加数据库连接
在默认的数据库连接以外，我们可以附加多个数据库连接，而且我们可以在开发中随时进行方便的调用，无需在每次使用时再进行一次连接数据库的操作。

##### 关于连接数据库，V3提供了如下几种用于连接的方法和属性：

|方法&属性|说明
| ------------ | ------------ |
|Easp.Db.OpenConnection（方法）|生成数据库连接字符串
|Easp.Db.CreateConnection（方法）|建立数据库连接对象
|Easp.Db.SetConnection（方法）|设置Connection对象
|Easp.Db.SetConn（方法）|设置默认Connection对象
|Easp.Db.GetConnection（方法）|取得Connection对象
|Easp.Db.GetConn（方法）|取得默认Connection对象
|Easp.Db.DefaultConn（属性）|接管外部Connection对象为默认连接

如果我们看一下数据库类的方法列表，我们会发现后面所有的查询插入更新删除的操作都会有两种方法，好，你只要记住，名称简单的方法就是用来操作默认数据库的，名称复杂的就是用来操作附加数据库的就行了。

在调用附加数据库之前，我们先取出它：`Set conn =  Easp.Db.GetConnection("connName")`，然后比如我们要查询记录集，查询的两个方法为：`Easp.Db.Select(conn, sql)` `Easp.Db.Sel(sql)`，看出来什么了，参数 `sql` 顾名思义就是查询的SQL语句，而 `Easp.Db.Select` 方法多了一个 `conn` 参数，这个参数就是我们取出的附加数据库对象，明白了嘛？

上面表中的方法，前两个我们基本用不上，我们从最常用的 `Easp.Db.SetConn` 方法开始讲解，注，这里我不会详细解释其参数，只是讲用法，便于大家系统地理解V3的数据库连接。

#### Easp.Db.SetConn
用来设置默认数据库，除非你的系统不使用数据库，否则这个方法是百分百会用到的。
我们可以在 `easyasp/easp.config.asp` 文件里进行配置，但我个人不建议这样做，因为如果我们更新EASP时覆盖了这个文件，你的系统就会处于无连接状态，至少的报错到你更新了这个文件里的连接数据库代码。所以建议大家在你系统的最开始的代码或引用的设置文件里进行设置。
当我们加上了这个方法连接好数据库之后，我们就可以使用数据库类的各种方法去操作数据库的数据了，记住，是**`名称简单的方法`**。

#### Easp.Db.SetConnection
如果你用到附加数据库，而且是很多个，那么我们在系统的写代码的开始就要对每个数据库进行连接设置，同 `Easp.Db.SetConn` 方法一样，我们也可以在 `easyasp/easp.config.asp` 文件里进行配置，但同样也不建议这么做。
比如：
```asp
Easp.Db.SetConnection "sql","MSSQL","dbname","sa:pass@(local)"
Easp.Db.SetConnection "acc",1,"db/_db.mdb",""
Easp.Db.SetConnection "mysql", "MYSQL", "dbname", "root:pass@10.0.0.5"
```
好，我们已经在默认数据库之外建立了三个数据库的连接，在使用时你会发现，每个操作数据库的方法里都会有一个 `conn` 参数，这个参数就是我们提前用 `Set conn =  Easp.Db.GetConnection("connName")` 取出的附加数据库。

注：有一个特殊的名称，`default`，如果你写了这个，那个相当于把默认连接用 `Easp.Db.SetConnection` 方法来设置了。

#### Easp.Db.GetConnection 和 Easp.Db.GetConn
这两个Get的方法，你可以理解为取得你设置好的默认和附加数据库连接字符串并生成一个数据库对象，举两个例子说明：
##### 1、从三个附加数据库中取出一个设为默认数据库连接
```asp
'默认数据库连接'
Easp.Db.SetConn "ACCESS", "/sampledata/EaspSampleData.mdb", ""
'再设三个附加的数据库连接'
Easp.Db.SetConnection "sql","MSSQL","dbname","sa:pass@(local)"
Easp.Db.SetConnection "acc",1,"db/_db.mdb",""
Easp.Db.SetConnection "mysql", "MYSQL", "dbname", "root:pass@10.0.0.5"
'取出一个附加的数据库连接用 Easp.Db.DefaultConn 属性设为默认数据库连接'
Easp.Db.DefaultConn = Easp.Db.GetConnection("sql")
'可以用默认的数据库方法查询了'
Set Rs = Easp.Db.Sel("select * from easp_test")
```
这里也捎带说明了一下 `Easp.Db.DefaultConn` 属性，它就是干这个用的。

##### 2、把默认库连接临时取出做为附加数据库使用
```asp
'默认数据库连接'
Easp.Db.SetConn "ACCESS", "/db/db.mdb", ""
'临时取出默认数据库并生成连接对象'
Set Conn = Easp.Db.GetConn
'用附加数据库的方法查询'
Set Rs = Easp.Db.Select(Conn, "select * from easp_test")
'关闭临时连接'
Set Conn = Nothing
```
可以把默认Connection对象Set给其他变量，并且关闭这个对象并不影响默认连接继续使用。

#### 关闭连接
关于关闭连接，你大可不必操心，因为EASP里每一个操作后，系统都会自动关闭，一般我们只会用到这个：
```asp
Easp.Db.Close Rs
```
关闭你的各种操作时新建的数据库对象，好习惯得养成，每页下面有一个就可以了。
<h4 class="font-thin"><label class="label bg-info text-white"><i class="fa fa-terminal"></i> 源码解析</label></h4>

core/easp.db.asp 第 146 行：
```asp
Public Function OpenConnection(ByVal dbType, ByVal strDB, ByVal strServer)
	Dim ConnStr, objConn, s, u, p, port
	s = "" : u = "" : p = "" : port = ""
	If Instr(strServer,"@")>0 Then
	  s = Trim(Mid(strServer,InstrRev(strServer,"@")+1))
	  u = Trim(Left(strServer,InstrRev(strServer,"@")-1))
	  If Instr(s,":")>0 Then : port = Trim(Mid(s,Instr(s,":")+1)) : s = Trim(Left(s,Instr(s,":")-1))
	  If Instr(u,":")>0 Then : p = Trim(Mid(u,Instr(u,":")+1)) : u = Trim(Left(u,Instr(u,":")-1))
	Else
	  If Instr(strServer,":")>0 Then
	    u = Trim(Left(strServer,Instr(strServer,":")-1))
	    p = Trim(Mid(strServer,Instr(strServer,":")+1))
	  Else
	    p = Trim(strServer)
	  End If
	End If
	Select Case dbType
	  Case "MSSQL"
	    ConnStr = "Provider=sqloledb;Data Source=" & s & Easp.IfThen(Easp.Has(port), "," & port) & ";Initial Catalog="&strDB&";User Id="&u&";Password="&p&";"
	  Case "ACCESS"
	    Dim tDb : If Instr(strDB,":")>0 Then : tDb = strDB : Else : tDb = Server.MapPath(strDB) : End If
	    ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&tDb&";Jet OLEDB:Database Password="&p&";"
	  Case "MYSQL"
	    If port = "" Then port = "3306"
	    ConnStr = "Driver={MySQL ODBC 5.1 Driver};Server="&s&";Port="&port&";Database="&strDB&";User="&u&";Password="&p&";Option=3;"
	End Select
	Set OpenConnection = CreateConnection(ConnStr)
End Function
```



</textarea>

</section>

														</section>
													</aside>
												</section>
											</section>
										</section>
									</section>
								</section>
							</section>
						</section>
					</section>
				</section>
			</section>
		</section>		
		<script src="../s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
		<script src="../s1.pstatp.com/cdn/expire-1-M/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
		<script src="../s2.pstatp.com/cdn/expire-1-M/jQuery-slimScroll/1.3.8/jquery.slimscroll.min.js"></script>
		<script src="../s1.pstatp.com/cdn/expire-1-M/prettify/r298/prettify.min.js"></script>
		<script src="inc/editor/lib/marked.min.js"></script>
		<script src="inc/editor/editormd.js"></script>
		<script src="inc/js/app.js"></script>
		<script src="inc/js/jquery.easysearch.js"></script>
		<script>
			
			$(function() {
				var testEditormdView;
				testEditormdView = editormd.markdownToHTML("test-editormd-view", {
					htmlDecode: "style,script,iframe",
					emoji: true,
					editorTheme : "pastel-on-dark",
					taskList: true
				});
			});
			$('input').jSearch({
				selector: 'table',
				child: 'tr > td > a',
				minValLength: 0,
				Before: function() {
					$('table tr').data('find', '');
				},
				Found: function(elem, event) {
					$(elem).parent().data('find', 'true');
					$(elem).parent().parent().show();
				},
				NotFound: function(elem, event) {
					if (!$(elem).parent().data('find'));
					$(elem).parent().parent().hide();
				},
				After: function(t) {
					if (!t.val().length) $('table tr').show();
				}
			});
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "../hm.baidu.com/hm3298.js?7758fff2e207d5773bc5d925a2606368";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
		</script>
	</body>

<!-- Mirrored from easp.jswwl.com/?api/Easp.Db.OpenConnection by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 13 Nov 2021 05:16:49 GMT -->
</html>